package com.neuedu.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.neuedu.pojo.Type;
import com.neuedu.service.ITypeService;
import com.neuedu.util.CommonResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author han
 * @since 2020-09-21
 */
@RestController
@RequestMapping("/type")
public class TypeController {
    @Resource
    ITypeService typeService;

    @GetMapping("/list")
    CommonResult list(Type type) {
        return CommonResult.success(typeService.list(type));
    }
    @PostMapping("/add")
    CommonResult add(Type type) {
        type.setActive(1);
        if(typeService.add(type))
            return CommonResult.success("添加项目种类成功");
        else
            return CommonResult.failed("此类已经存在");
    }
    @GetMapping("/getById")
    CommonResult getById(Integer id) {
        return CommonResult.success(typeService.getById(id));
    }
    @PostMapping("/update")
    CommonResult update(Type type) {
        return CommonResult.success(typeService.updateById(type));
    }
    @PostMapping("/del")
    CommonResult del(Type type) {
        type.setActive(0);
        return CommonResult.success(typeService.updateById(type));
    }
    @PostMapping("/batchdel")
    CommonResult batchdel(Integer[] ids) {
        return CommonResult.success(typeService.batchdel(ids));
    }
    @PostMapping("/back")
    CommonResult back(Type type) {
        type.setActive(1);
        return CommonResult.success(typeService.updateById(type));
    }
    @GetMapping("getAll")
    CommonResult getAll(){
        QueryWrapper<Type> qu =new QueryWrapper<>();
        qu.eq("active",1);
        return CommonResult.success(typeService.list(qu));
    }

}
